<?php
class Status extends CI_Controller
{
 public function _construct()
 {
   parent::_construct();
 }
 /**
  public function index()
  {
   
   $sql="Select*from status order by status_id asc";
   $rs=$this->db->query($sql);

   $data["rs"] = $rs->result_array();
   $this->load->view("status/index",$data);
  }
  public function add()

	{
		if($this->input->post("dtsave")!=null)
		{
		$ar=array(
		   "status_date"=>$this->input->post("status_date"),	
		   "status_type"=>$this->input->post("status_type"),
		   "status_room"=>$this->input->post("status_room"),
		   "status_detail"=>$this->input->post("status_detail"));

		$this->db->insert("status",$ar);

		redirect("status/index","refresh");
		exit();
		}
      $this->load->view("status/add");
     }

	 
 public function del($status_id)
	{
	 $this->db->delete("status",array("status_id"=>$status_id));
	 redirect("status","refresh");
	 exit();
	}
	**/

	public function index()
	{
		$sql="Select*from status order by statid";
		$rs=$this->db->query($sql);

		$data['rs'] = $rs->result_array();
		$this->load->view("status/index",$data);
	}
	public function add()
	{
		$this->load->view('status/add');
	}
	public function add_data()
	{
		/**
		echo $this->input->post('date');
		echo $this->input->post('type');
		echo $this->input->post('room');
		echo $this->input->post('detail');
		**/
		$ar=array(
		   "statid" => null,
		   "statdate"=>$this->input->post("date"),	
		   "stattype"=>$this->input->post("type"),
		   "roomname"=>$this->input->post("room"),
		   "roomstat"=>$this->input->post("num"),
		   "statdetail"=>$this->input->post("detail"));

		$this->db->insert("status",$ar);
		redirect("status","refresh");
		 exit();
	}

	public function edit()
	{
	  $id=$this->uri->segment(3);
	  $sql="Select*from status where statid='$id'";
	  $rs=$this->db->query($sql);

	  if($rs->num_rows()==0)
		{
	       $data['rs']=array();  
	    }
		else
		{
		  $data['rs']=$rs->row_array();  
		}
	  $this->load->view("status/edit",$data);

	}

	public function update()
	{
		$status_id = $this->uri->segment(3);
		
		   $status_date = $this->input->post("date");
		   $status_type = $this->input->post("type");
		   $status_room = $this->input->post("room");
		   $status_num = $this->input->post("num");
		   $status_detail = $this->input->post("detail");

		$sql = "Update status set statdate='$status_date',stattype='$status_type',roomname='$status_room',roomstat=$status_num,statdetail='$status_detail' where statid=$status_id;";
		$this->db->query($sql);
		redirect("status","refresh");
		 exit();
	}
	public function del($id)
	{
	     $this->db->delete('status', array('statid' => $id)); 
		 redirect("status","refresh");
		 exit();

     }


}	


